package com.derbysoft.dswitch.adapter.ihg.web.action.admin.setting.rateplan;

import com.derbysoft.dswitch.adapter.ihg.common.domain.RatePlan;
import com.derbysoft.dswitch.adapter.ihg.common.repository.RatePlanRepository;
import com.derbysoft.dswitch.adapter.ihg.web.action.support.BaseAction;
import org.apache.commons.lang.StringUtils;
import org.apache.struts2.convention.annotation.Action;
import org.springframework.beans.factory.annotation.Autowired;

public class EditAction extends BaseAction {
    @Autowired
    private RatePlanRepository ratePlanRepository;

    private String ratePlanCode;

    private RatePlan ratePlan;

    private RatePlan oldRatePlan;


    @Action("update")
    public String update() {
        ratePlanRepository.save(ratePlan);
        return LIST;
    }

    @Action("view")
    public String view() {
        if (StringUtils.isBlank(ratePlanCode)) {
            return EDIT;
        }
        oldRatePlan = ratePlanRepository.loadByCode(ratePlanCode);
        return EDIT;
    }

    public RatePlan getOldRatePlan() {
        return oldRatePlan;
    }

    public void setOldRatePlan(RatePlan oldRatePlan) {
        this.oldRatePlan = oldRatePlan;
    }

    public RatePlan getRatePlan() {
        return ratePlan;
    }

    public void setRatePlan(RatePlan ratePlan) {
        this.ratePlan = ratePlan;
    }

    public String getRatePlanCode() {
        return ratePlanCode;
    }

    public void setRatePlanCode(String ratePlanCode) {
        this.ratePlanCode = ratePlanCode;
    }
}
